using System;

namespace HpcClusterControllerLinux
{
    class Shell
    {
		public static string LastError;
		
        public static string run(string cmd, string args)
        {
			string output = null;
			try {
				System.Diagnostics.Process processo = new System.Diagnostics.Process();
				processo.EnableRaisingEvents = false; 
				processo.StartInfo.FileName = cmd;
	            processo.StartInfo.Arguments = args;
				processo.StartInfo.RedirectStandardOutput = true;
				processo.StartInfo.RedirectStandardError = true;
				processo.StartInfo.UseShellExecute = false;
				
				processo.Start();
				if (!processo.HasExited)
					processo.WaitForExit();
				
				output = processo.StandardOutput.ReadToEnd();	
				LastError = processo.StandardError.ReadToEnd();
				
			} catch (Exception ex) {
				Console.WriteLine(ex.Message);
			}
			
			return output;
        }
    }
}
